//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.taofuxn.admin.common.model;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Data
public class PageResponse<T> implements Serializable {
    private static final long serialVersionUID = 7066961328399416219L;
    private long totalCount = 0L;
    private int totalPage;
    private int pageSize = 10;
    private int currPage = 1;
    private List<T> list = new ArrayList();

    public PageResponse() {
    }

    public PageResponse(long totalCount, int pageSize, int currPage, List<T> list) {
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.currPage = currPage;
        this.list = list;
    }

    public static <T> PageResponse<T> success(List<T> list, int currPage, int pageSize, long totalCount) {
        return list == null ? empty(currPage, pageSize) : new PageResponse(totalCount, pageSize, currPage, list);
    }

    public static <T> PageResponse<T> empty(int currPage, int pageSize) {
        return new PageResponse(0L, pageSize, currPage, Collections.emptyList());
    }


    public int getTotalPage() {
        int total = (int)this.totalCount;
        if (total < this.pageSize) {
            return 1;
        } else {
            return total % this.pageSize == 0 ? total / this.pageSize : total / this.pageSize + 1;
        }
    }


}
